package com.geekca.duotai;

import java.util.Locale;

public class TestMain {

    public static void main(String[] args) {
        // 父类引用       子类对象, 子类对象是一个父类类型
        Animal animal = new Dog();
        animal.setName("旺财");
        System.out.println(animal.getName());
        animal.shout();

        Animal cat = new Cat();
        cat.shout();

        System.out.println("============================");
        Animal a1 = new Dog();
        a1.setName("banDianGou ");

        Animal a2 = new Cat();
        a2.setName("bosimao");

        showAnimal(a1);
        showAnimal(a2);
    }

    public static void showAnimal(Animal animal){
        System.out.println(animal.getName().toUpperCase());
        // 无法使用子类独有的行为
        if (animal instanceof Cat) {
            System.out.println("我是猫");
            ((Cat) animal).catchMouse();

        }
    }

}
